<template>
  <div>
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      :append-to-body="true"
      :before-close="cancel"
      :show-close="true"
      title="下发信息选择"
      width="75%"
      @opened="searchHandle"
    >
      <!-- 查询条件 -->
      <div class="searchform">
        <el-form
          ref="addDiaForm"
          :rules="rules"
          :inline="true"
          :model="search"
          size="mini"
          label-width="100px"
          label-position="right">
          <el-form-item prop="series_id" label="产品小类">
            <r-select
              v-validate="'required'"
              v-model="search.series_id"
              selectid="series_id"
              selectname="series_name"
              url="/productDisplay/getTmSeies"
              model="DMSCLOUD_VEHICLE"
              placeholder="请选择车系"
              filterable
            />
          </el-form-item>
          <el-form-item prop="dealer_name" label="经销商">
            <el-input v-model="search.dealer_name" readonly>
              <i slot="suffix" class="el-input__icon el-icon-circle-plus" @click="dealerOpen"/>
              <!-- <i slot="suffix" class="el-input__icon el-icon-error" @click="dealerClose"/> -->
            </el-input>
          </el-form-item>
          <!-- <el-form-item prop="dealer_code" label="经销商代码">
            <el-input v-model="search.dealer_code" placeholder="经销商代码" class="search-input" clearable />
          </el-form-item> -->
          <!-- <div style="text-align:center">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="searchHandle">查询
              </el-button>
            </el-form-item>
            <el-form-item>
              <el-button icon="el-icon-refresh" @click="resetForm('searchForm')">重置
              </el-button>
            </el-form-item>
          </div> -->
        </el-form>
      </div>
      <!-- <div class="table">
        <div class="tableHead">
          <div class="tabletitle">代理商信息</div>
        </div> -->
      <!-- 用户列表 -->
      <!-- <BaseTable
          ref="table"
          highlight-current-row
          @chaneg-size="changeSizeHandle"
          @chaneg-page="changePageHandle"
          @current-change="select"
        >
          <el-table-column label="序号" type="index" />
          <el-table-column :show-overflow-tooltip="true" prop="dealer_name" label="经销商名称" min-width="150"/>
          <el-table-column prop="dealer_code" label="经销商代码" min-width="150"/>
          <el-table-column prop="province_name" label="省" min-width="150"/>
          <el-table-column prop="city_name" label="市" min-width="150"/>
          <el-table-column prop="longitude" label="经度" min-width="150"/>
          <el-table-column prop="latitude" label="维度" min-width="150"/>
          <el-table-column prop="is_pay_name" label="是否交付中心" min-width="150"/>
          <el-table-column prop="is_ty_name" label="是否体验中心" min-width="150"/>
        </BaseTable> -->
      <!-- </div> -->
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button type="text">
          <i style="top:12px" class="el-icon-search magnifier" />
        </el-button>
        <el-button type="primary" @click="confirmHandle" >确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <dealerSelect :open-select-dealer.sync="openSelectDealer" @dealerClose="dealerClose" @getDealerInfo="dealerInfo"/>
    <sellSelect v-if="openSelectSell" :open-select-sell.sync="openSelectSell" :dealer-code="search.dealer_code" @sellClose="sellClose" @getSellInfo="sellInfo"/>
  </div>
</template>

<script>
import { queryPageInfos4dealer } from '@/api/vehicle/dealer.js'
import { issued4custBiz } from '@/api/vehicle/custBiz.js'
import filtercode from '@/components/Checkbox/filtercode'
import BaseTable from '@/components/BaseTable'
import formMixins from '@/mixins/formMixins'
import rSelect from '@/components/Select/Select'
import dealerSelect from '@/views/admin/auth/gms/userDrive/selectDealer.vue'
import sellSelect from '@/views/admin/auth/gms/userDrive/selectSell.vue'

export default {
  name: 'AfterDealer',
  components: {
    BaseTable,
    filtercode,
    dealerSelect,
    sellSelect,
    rSelect

  },
  mixins: [formMixins],
  props: {
    dialogFormVisible: false,
    closeValue: ''
  },
  data() {
    return {
      loading: false,
      openSelectDealer: false,
      openSelectSell: false,
      multipleSelection: [],
      search: {
        limit: 10,
        pageNum: 1,
        dealer_code: '',
        dealer_name: '',
        series_id: ''
      },
      rules: {
        series_id: [{
          required: true,
          message: '请选择车系'
        }],
        dealer_name: [{
          required: true,
          message: '请选择经销商'
        }]
      }
    }
  },

  computed: {},
  mounted() {
    // this.searchHandle();
  },
  methods: {
    searchHandle() {
      // this.search.limit = 5
      const table = this.$refs['table']
      queryPageInfos4dealer(this.search)
        .then(res => {
          table.complete().filData(res)
        })
        .catch(err => {
          table.complete()
        })
    },
    // 从经销商选择框获取信息
    dealerInfo(dealerInfo) {
      if (dealerInfo != '') {
        this.$set(this.search, 'dealer_name', dealerInfo.DEALER_NAME)
        this.search.dealer_code = dealerInfo.DEALER_CODE
      }
    },

    cancel() {
      this.$emit('update:dialogFormVisible', false)
    },
    // 打开经销商选择框
    dealerOpen() {
      this.openSelectDealer = true
      this.editDialog = false
    },
    dealerClose() {
      this.editDialog = true
      this.openSelectDealer = false
    },
    // 销售顾问框关闭
    sellClose() {
      this.editDialog = true
      this.openSelectSell = false
    },
    // 发票订单选择
    select(val) {
      if (val == null) {
        this.multipleSelection = []
      } else {
        this.multipleSelection = val
      }
    },
    confirmHandle() {
      const that = this

      this.$refs['addDiaForm'].validate(valid => {
        if (valid) {
          // this.validatebefSave()
          // const that = this
          // this.saveLoading = true
          // if (!this.fileList4cover || this.fileList4cover.length == 0) {
          // this.$message({
          //   type: 'warning',
          //   message: '请上传图片！'
          // })
          // this.saveLoading = false
          // return false
          // }
          console.log(this.closeValue)
          const confirmText = '确认下发【' + this.closeValue.customer_name + '】？'
          this.$confirm(confirmText, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            center: true
          }).then(() => {
            issued4custBiz({ user_id: this.closeValue.user_id, dealer_code: this.search.dealer_code, series_id: this.search.series_id }).then(res => {
              that.$message.success('操作成功！')
              that.cancel()
              that.searchHandle()
            })
          }).catch(() => {

          })
        } else {
          this.$message({
            type: 'warning',
            message: '请完成填写'
          })
          this.saveLoading = false
          this.fullscreenLoading = false
        }
      })

      // this.$emit('getAfterDealerInfo', this.multipleSelection)
      // this.$emit('update:dialogFormVisible4dealer', false)
      // if (this.multipleSelection.length === 0) {
      //   this.$message({
      //     type: 'warning',
      //     message: '请选择数据!'
      //   })
      // } else {
      //   this.$emit('getAfterDealerInfo', this.multipleSelection)
      //   this.$emit('update:dialogFormVisible', false)
      // }
    }

  }
}
</script>

<style scoped>

.magnifier {
  float: right;
  position: absolute;
  right: 50px;
  top: 23px;
  cursor: pointer;
}
</style>
